define(function (require,exports,module) {
    var sTpl = require("./template.html");
    //var enter = require("../enter/enter.js");
    var VueComponent = Vue.extend({
        props: ['parentData'],
        template: sTpl,
        // components:{
        //     'enters':enter
        // },
        data:function () {
            this.$route.params.type;
            
            return {
                form:{
                    startDate:'',
                    endDate:'',
                    flightNum:'',
                    flightInfoId:'',
                    scheduled:true,
                    unScheduled:true,
                },
                url:basepath+"/api/flightPlane/queryScheduling?",
                planes:[],
                enterOpen:true,
                currentPlane:{},
                currentService:{},
                allUser:[],
                transferResult:[],
                dialog:false,
                enterData:{
                    editOrAdd:'add'
                },
                addScheduling:{
                    edit:false,
                    consumeTime:"",
                    groundServiceItemPo:{gsiId:''},
                    groundServiceItemPoGsiId:"",
                    groundServiceSchedulings:{id:""},
                    selectedUser:[],
                    status:"发布"
                },
                serviceItems:[]
                ,
                slidingWindowVisible1:false
            }
        },methods:{
            handleSelectItem:function(value){
              this.addScheduling.groundServiceItemPo= this.serviceItems.filter(function (data) {
                  if(data.gsiId==value)return  data;
              })[0];
            },
            queryFlightPlane:function () {
                this.openEnter(false);
                var url=basepath+"/api/flightPlane/queryScheduling?startDate="+this.form.startDate+"&scheduled="+(this.form.scheduled==this.form.unScheduled?'':this.form.scheduled)
                    +"&endDate="+this.form.endDate+"&flightInfoId="+(this.form.flightInfoId?this.form.flightInfoId:"");
                this.url=url;
            },
            handleSelect:function (val) {
                this.form.flightInfoId=val.flightInfoId;
            },
            pickEndDate:function (val) {
                this.form.endDate= val;
            },
            startAddScheduling:function () {
                this.addScheduling.edit=true;
            },
            confirmAddSchediling:function () {
                this.addScheduling.groundServiceSchedulings.id = this.currentPlane.groundServiceSchedulings.id;
                this.addScheduling.edit=false;
                this.currentPlane.groundServiceSchedulings.schedulings.unshift(this.addScheduling);
            },
            cancleAddScheduling:function () {
                this.addScheduling={
                    edit:false,
                    consumeTime:"",
                    groundServiceItemPo:{gsiId:''},
                    groundServiceSchedulingsId:"",
                    groundServiceSchedulings:{id:""},
                    selectedUser:[],
                    status:"发布"
                }
            },
            pickStartDate:function (val) {
                this.form.startDate= val;
            },
            openEnter:function (val) {
                this.enterOpen=!val;
                $("#panel-activer").prop("checked",val);
            },edit:function (scope,index) {
                var $this = this;
                $this.slidingWindowVisible1 = true;
                axios.post(basepath+"/api/flightPlane/scheduleOneFlight",scope.row.flightPlane).then(function (response) {
                    scope.row.groundServiceSchedulings=response.data.groundServiceSchedulings;
                    $this.currentPlane=scope.row;
                });

            },
            editItem:function (scope,index) {
                this.allUser =scope.groundServiceItemPo.selectAbleUser.map(function(value){
                    value.userCnName =value.selectAbleUser.userCnName
                    value.userName =value.selectAbleUser.userName
                    return value
                });
                this.transferResult = scope.selectedUser.map(function (value) {
                    value.userCnName =value.selectAbleUser.userCnName
                    value.userName =value.selectAbleUser.userName
                    return value;
                });
                this.currentService = scope;
                this.dialog = true;
                scope.edit=true;
                this.$set(this.currentPlane.groundServiceSchedulings.schedulings,index,this.currentPlane.groundServiceSchedulings.schedulings[index])
            },
            show:function (scope){
                //this.currentPlane=;
                this.addScheduling.edit=false
                scope.row.groundServiceSchedulings.schedulings.forEach(function (data) {
                     data.edit=false;
                 })
                this.$set(this.currentPlane,'flightPlane',scope.row.flightPlane);
                this.$set(this.currentPlane,'groundServiceSchedulings',scope.row.groundServiceSchedulings);
                this.slidingWindowVisible1 = true;
            },
            deleteOneScheduling:function(scope,index){
                var $this = this;
                this.$confirm('删除后将无法恢复', '确定该服务？', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    axios.post(basepath+'/api/flightPlane/deleteOneSchedule',scope)
                        .then(function (response) {
                            $this.currentPlane.groundServiceSchedulings.schedulings.splice(index,1);
                            $this.$notify({
                                title: '删除成功',
                                message: '服务项已删除'
                            });
                        });
                })
            },
            updateSelectdUser:function (item,index) {
                item.edit= false;
                var $this = this;
                this.$set(this.currentPlane.groundServiceSchedulings.schedulings,index,this.currentPlane.groundServiceSchedulings.schedulings[index])
                item.groundServiceSchedulings={};
                item.groundServiceSchedulings.id=this.currentPlane.groundServiceSchedulings.id;
                axios.post(basepath+"/api/flightPlane/saveOneSchedule",item).then(function (response) {
                    $this.$notify({title:"更新成功",message:"派遣员工更新成功"})
                })

            },
            confirm:function () {
                this.currentService.selectedUser =  this.transferResult;
                this.dialog=false;
            }

        },
        created:function () {

            var $this=this;
            axios.get("/dam/api/flightInfo/queryFlightInfo?filter=").then(function (response) {
                $this.planes=response.data;
                $this.planes.forEach(function(plane){
                    plane.value= plane.flightNum;
                })
            });
            axios.get(basepath+'/api/flightPlane/queryAllScheduleItem')
                .then(function (response) {
                    $this.serviceItems=response.data;
                });
        },
        activated:function () {
            messages.$emit('change','航班计划');
        }
    })
    module.exports=VueComponent;
})